/**
 * Created by Alexis on 28/04/14.
 * @return {boolean}
 */
// ==================
//	Activations - Désactivations
// ==================
function GereControle(Controleur, Controle, Masquer) {
    var objControleur = document.getElementById(Controleur);
    var objControle = document.getElementById(Controle);
    if (Masquer=='1')
        objControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
    else
        objControle.disabled=(objControleur.checked != true);
    return true;
}

$(document).ready(function(){

    var clic = 0;
    var idp = '';

    $('.lightbox').nivoLightbox();

    $('.change').change(function () {

        var cb = $(this);
        var slt = $('.changer');

        if(cb.is(':checked')) {
            slt.show();
            slt.attr('required');
        } else {
            slt.hide();
            slt.removeAttr('required');
        }
    });

    $('.change_imp').click(function(){

        var ligne = $(this).attr('id');
        ligne = ligne.split('-');
        ligne = ligne[1];
        var param = $('.changer_imp'+ligne);
        // if(clic == 0){
            param.show();
        // }else{
        var but = $('.change_imp'+ligne);
        if(param.length > 0){
            but.hide();
        }

        param.change(function(){
            var li = $('#ligne');
            if(li.length > 0){
                li.remove();
            }
            var ligneStr = $('<input type="hidden" value="'+ligne+'" name="ligne" id="ligne"/> ');
            ligneStr.appendTo('.form_imp');
            if(param.length > 2){
                if(idp == ''){
                    idp = this.id;
                }
                else if(idp != this.id ){
                    idp = this.id;
                    $('.submit'+ligne).click();
                }
            }else{
                $('.submit'+ligne).click();
            }
        });


        // }
        clic += 1;
    });

    $('input[type=radio][name=relance]').change(function(){
        var rel = $('input[type=radio][name=relance]:checked').attr('value');

        $('.val_relance').val(rel);

    });

});


